<template>
	<div class="amendDuty addDuty">
		<!-- 面包屑 -->
		<el-breadcrumb separator=">" class="crumbs">
			<el-breadcrumb-item :to="{ path: '/duty'}">职位管理</el-breadcrumb-item>
			<el-breadcrumb-item :to="{ path: '/amendDuty'}">修改职位</el-breadcrumb-item>
		</el-breadcrumb>
		<!-- 修改职位的条件 -->
		<el-row :gutter="20">
			<el-col :span="8" class="roleText roleStyle">职位编号</el-col>
			<el-col class="roleStyle" :span="16">
				<el-input placeholder="请输入内容" v-model="positionCode" :disabled='true'></el-input>
			</el-col>
			<el-col :span="8" class="roleText roleStyle">职位名称</el-col>
			<el-col class="roleStyle" :span="16">
				<el-input placeholder="请输入内容" v-model="positionName" @keyup.native="delSpace('positionName')"></el-input>
			</el-col>
			<el-col :span="8" class="roleText roleStyle">职位描述</el-col>
			<el-col class="roleStyle" :span="16">
				<el-input placeholder="请输入内容" v-model="positionDescription" @keyup.native="delSpace('positionDescription')"></el-input>
			</el-col>
		</el-row>
		<!-- 添加列表完成  以下是按钮 -->
		<el-row class="addUserBtn">
			<el-col :sm="9" :xs="6">&emsp;</el-col>
			<el-col :sm="3" :xs="6">
				<el-button type="primary" @click="save">保存</el-button>
			</el-col>
			<el-col :sm="3" :xs="6">
				<el-button @click='cancel'>取消</el-button>
			</el-col>
			<el-col :sm="9" :xs="6">&emsp;</el-col>
		</el-row>
	</div>
</template>

</div>
</template>

<script>
	export default {
		name: 'amendDuty',
		data() {
			return {
				positionCode: '',
				positionName: '',
				positionDescription: '',
				states: [
					{ label: '有效', value: '1' },
					{ label: "无效", value: '0' }
				],
				isEffect: ''
			}
		},
		methods: {
			delSpace (str) {
				this[str]  = this[str].replace(/\s/g,"");
			},
			save () {
				var condition = {
					positionCode: this.positionCode,
					positionName: this.positionName,
					positionDescription: this.positionDescription,
					isEffect: this.isEffect
				}
				if (!condition.positionName) {
					this.$message({
						type: "warning",
						message: "请填写职位名称",
						duration: 1500,
						showClose: true
					})
					return
				}
				if (condition.positionName.length > 20) {
					this.$message({
						message: '职位名称不能大于20个字符',
						type: 'error',
						duration: 1500,
						showClose: true
					})
					return
				}
				if (condition.positionDescription.length > 40) {
					this.$message({
						message: '职位描述不能大于40个字符',
						type: 'error',
						duration: 1500,
						showClose: true
					})
					return
				}
				this.$http.post(this._path + '/positionManage/updatePosition', condition).then((res) => {
					if ("0000" == res.data.resultCode) {
						this.$message({
							message: '修改成功',
							type: 'success',
							duration: 1500,
							showClose: true
						})
						this.$router.push('/duty');
					} else {
						this.requestError(res, this)
					}
				})
			},
			cancel() {
				this.$router.push('/duty')
			}
		},
		created() {
			this.positionCode = this.$route.query.id
			this.$http.post(this._path + '/positionManage/selectPositionInfo', { positionCode: this.$route.query.id }).then((res) => {
				if ("0000" == res.data.resultCode) {
					this.positionName = res.data.data.positionName;
					this.positionDescription = res.data.data.positionDescription
				} else {
					this.requestError(res, this)
				}

			})
		},
		mounted() {

		}
	}

</script>

<style scoped lang="scss">
	@import "./../style/addDuty.scss"
</style>